package org.example.afree;

public class plus_one {
    public int[] plusOne(int[] digits) {
        return plusOne2(digits, digits.length-1);
    }

    public int[] plusOne2(int[] digits,int index) {
        if (index == -1){
            int[] res = new int[digits.length + 1];
            res[0] = 1;
            for (int i = 1; i < res.length; i++) {
                res[i] = digits[i-1];
            }
            return res;
        }
        if (digits[index]+1 > 9){
            digits[index] = 0;
            return plusOne2(digits,index-1);
        }else {
            digits[index] = digits[index]+1;
            return digits;
        }

    }
}
